package pro.shushi.pamirs.demo.core.action;

import org.springframework.stereotype.Component;
import pro.shushi.pamirs.demo.api.model.Product;
import pro.shushi.pamirs.meta.annotation.Action;
import pro.shushi.pamirs.meta.annotation.Model;
import pro.shushi.pamirs.meta.annotation.fun.extern.Slf4j;
import pro.shushi.pamirs.meta.enmu.ActionContextTypeEnum;
import pro.shushi.pamirs.meta.enmu.ViewTypeEnum;

@Slf4j
@Component
@Model.model(Product.MODEL_MODEL)
public class ProductAction {


    @Action(displayName = "上架",bindingType = ViewTypeEnum.TABLE,contextType = ActionContextTypeEnum.SINGLE)
    @Action.Advanced(invisible = "context.activeRecord.status == 'ture'")
    public Product itemActive(Product data) {
        Product update = new Product();
        update.setId(data.getId());
        update.setStatus(Boolean.TRUE);
        update.updateById();
        return data;
    }

    @Action(displayName = "下架",bindingType = ViewTypeEnum.TABLE,contextType = ActionContextTypeEnum.SINGLE)
    @Action.Advanced(invisible = "context.activeRecord.status == 'false'")
    public Product itemInActive(Product data) {
        Product update = new Product();
        update.setId(data.getId());
        update.setStatus(Boolean.FALSE);
        update.updateById();
        return data;
    }

}
